<template>
    <view class="pages">
        <view class="list-item" v-for="item in CircleList" :key="item.id" @click="selectCircle(item.circleInfo)">
            <view class="list-item-left">
                <img :src="item.circleInfo.thumb_img_url"/>
            </view>
            <view class="list-item-center">
                <text>{{item.circleInfo.name}}</text>
            </view>
            <view class="list-item-right">
                <img src="/static/img/right.png" />
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        name: "selectCircles",
        data(){
            return{
                CircleList: [],
            }
        },
        onShow(){
          this.getFollowCircleList()
        },
        methods:{
            //获取圈子列表
            async getFollowCircleList(){
                let params = {
                    page: 1,
                    limit: 100,
                    user_token: uni.getStorageSync('userToken')
                }
                const res = await this.$api.getFollowCircleList(params);
                if (res.data.level == 'success'){
                    if (res.data.data.length>0){
                        this.CircleList = res.data.data;
                    } else {
                        getApp().globalData.Num = 1;
                        uni.showToast({
                            icon:'none',
                            title:"您还未关注圈子~请先关注圈子~",
                            duration: 5000
                        })
                        setTimeout(function () {
                            uni.switchTab({
                                url:'/pages/circlebar/circlebar'
                            })
                        },5000)
                    }
                }else {
                    uni.showToast({
                        icon:'none',
                        title:res.data.message
                    })
                }
            },
            //选中
            selectCircle(item){
                let pages = getCurrentPages();
                let prevPage = pages[pages.length - 2];
                prevPage.setData({
                    postNames:{
                        name : item.name,
                        id : item.id
                    }
                })
                uni.navigateBack({
                    delta: 1
                })
            }
        }
    }
</script>

<style scoped lang="scss">
    .pages{
        padding: 3vw;
        display: flex;
        flex-direction: column;
        .list-item{
            display: flex;
            flex-direction: row;
            justify-content: left;
            padding: 10rpx 0;
            .list-item-left{
                width: 15vw;
                height: 15vw;
            }
            .list-item-center{
                width: 60vw;
                display: flex;
                align-items: center;
                padding: 0 2vw;
            }
            .list-item-right{
                width: 7vw;
                height: 7vw;
                padding: 4vw;
            }
        }
    }
</style>